package com.hrg.rds.biz.waybill.controller;

import com.hrg.rds.biz.waybill.domain.instance.WaybillInstanceDto;
import com.hrg.rds.biz.waybill.domain.instance.WaybillInstanceVo;
import com.hrg.rds.biz.waybill.domain.template.TemplateParam;
import com.hrg.rds.biz.waybill.service.WaybillInstanceService;
import com.hrg.sys.framework.web.controller.BaseController;
import com.hrg.sys.framework.web.domain.AjaxResult;
import com.hrg.sys.framework.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/open/waybillInstance")
public class WaybillInstanceController extends BaseController {

    @Autowired
    private WaybillInstanceService waybillInstanceService;

    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public TableDataInfo list(WaybillInstanceDto waybillInstanceDto) {
        startPage();// pageNum, pageSize, orderByColumn, isAsc 分页参数写在查询串
        List<WaybillInstanceVo> list = waybillInstanceService.selectList(waybillInstanceDto);
        return getDataTable(list);
    }

    // 暂停导航
    @GetMapping("/pause/{waybillInstanceId}")
    public AjaxResult pause(@PathVariable String waybillInstanceId) {
        return toAjax(waybillInstanceService.pause(waybillInstanceId));
    }
    // 恢复导航
    @GetMapping("/resume/{waybillInstanceId}")
    public AjaxResult resume(@PathVariable String waybillInstanceId) {
        return toAjax(waybillInstanceService.resume(waybillInstanceId));
    }

    // 终止运单
    @GetMapping("/terminate/{waybillInstanceId}")
    public AjaxResult terminate(@PathVariable String waybillInstanceId) {
        return toAjax(waybillInstanceService.terminate(waybillInstanceId));
    }

    @PostMapping("/fire/{waybillTemplateId}")
    public AjaxResult fireInstance(@PathVariable String waybillTemplateId, @RequestBody(required = false) List<TemplateParam> param, @RequestParam(required = false) String externalId) {
        return waybillInstanceService.fireInstance(waybillTemplateId, param, externalId);
    }
    
}
